package str

import (
	"strconv"
	"strings"
)

func dayOfYear(date string) int {

	dateList := strings.Split(date, "-")

	year, _ := strconv.Atoi(dateList[0])
	month, _ := strconv.Atoi(dateList[1])
	day, _ := strconv.Atoi(dateList[2])

	res := 0

	for i := 1; i < month; i++ {
		switch i {
		case 1, 3, 5, 7, 8, 10, 12:
			res += 31
		case 4, 6, 9, 11:
			res += 30
		case 2:
			isRun := helper(year)
			if isRun {
				res += 29
			} else {
				res += 28
			}
		}
	}

	return res + day

}

func helper(year int) bool {
	isRun := false

	if (year%4 == 0 && year%100 != 0) || (year%400 == 0) {
		isRun = true
	}

	return isRun

}
